using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class pages_SearchBox : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LocationDAO daoLoc = new LocationDAO();
            cmbLocation.DataSource = daoLoc.GetAllLocations();
            cmbLocation.DataTextField = "Name";
            cmbLocation.DataValueField = "Id";
            cmbLocation.DataBind();

            //Quantity of hotels
            cmbQuantity.Items.Add(new ListItem("All","-1"));
            cmbQuantity.Items.Add(new ListItem("1 Stars", "1"));
            cmbQuantity.Items.Add(new ListItem("2 Stars", "2"));
            cmbQuantity.Items.Add(new ListItem("3 Stars", "3"));
            cmbQuantity.Items.Add(new ListItem("4 Stars", "4"));
            cmbQuantity.Items.Add(new ListItem("5 Stars", "5"));
            LoadPriceRange();
        }
    }

    /// <summary>
    /// Load price range into drop down list in search box
    /// </summary>
    public void LoadPriceRange()
    {
        StreamReader sr=null;
        try
        {
            sr = new StreamReader(Server.MapPath("TourPriceRange.txt"));
            string st = "";
            while ((st = sr.ReadLine()) != null)
            {
                string[] info = st.Split(',');
                txtSPrice.Items.Add(new ListItem(info[0], info[1]));
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
           if(sr!=null) sr.Close();
        }
    }
    protected void btnSearchTour_Click(object sender, EventArgs e)
    {
        Response.Redirect("Search.aspx?mode=tour&loc="+cmbLocation.SelectedValue+"&s="+txtSKeyword.Text+"&"+txtSPrice.SelectedValue);
    }
    protected void btnSearchHotel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Search.aspx?mode=hotel&loc="+cmbLocation.SelectedValue+"&s="+txtHotel.Text+"&quality="+cmbQuantity.SelectedValue);
    }
    protected void btnSearhRestaurant_Click(object sender, EventArgs e)
    {
        Response.Redirect("Search.aspx?mode=rest&loc="+cmbLocation.SelectedValue+"&s="+txtRestaurant.Text);
    }
    protected void txtSPrice_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    public string GetActiveTab()
    {
        if (Request["active"] == null) return "s_tour";
        return Request["active"];
    }
}
